#include <stdio.h>
#include <ctype.h>
char *i2c(int ascii, char *c)
{
    c[0] = ' ';
    c[1] = ' ';
    c[3] = ' ';
    c[2] = '\\';
    switch (ascii)
    {
    case 7:
        c[3] = 'a';
        break;
    case 8:
        c[3] = 'b';
        break;
    case 9:
        c[3] = 't';
        break;
    case 10:
        c[3] = 'n';
        break;
    case 11:
        c[3] = 'v';
        break;
    case 12:
        c[3] = 'f';
        break;
    case 13:
        c[3] = 'r';
        break;
    case 32:
        c[2] = 'S';
        c[3] = 'P';
        break;
    default:
        if (ascii >= 128)
        {
            c[2] = '?';
            c[3] = '?';
        }
        else
        {
            if (iscntrl(ascii))
            {
                c[2] = 'c';
                c[3] = 't';
            }
            else
            {
                c[2] = ' ';
                c[3] = ascii;
            }
        }
    }
    return c;
}
int main()
{
    FILE *fp = NULL;
    fp = fopen("hello.c", "r");
    int line_n = 0;
    int eof = 0;
    char str[64];
    int ascii[16];
    while (eof != 2)
    {
        int x;
        x = (int)fgetc(fp);
        if (x == -1)
        {
            eof = 1;
        }
        ascii[line_n] = x;
        char c[4];
        i2c(x, c);
        for (int i = 0; i < 4; i++)
        {
            str[line_n * 4 + i] = c[i];
        }

        line_n++;
        if (line_n >= 16)
        {
            for (int i = 0; i < 64; i++)
            {
                if (str[i]!=-1){
                printf("%1c", str[i]);}
            }
            printf("\n");
            for (int i = 0, flag = 0; i < 16; i++)
            {
                if (ascii[i] == -1 & flag != 1)
                {
                    printf(" EOF");
                    flag = 1;
                }
                else
                {
                    if (flag != 1)
                        printf("%4d", ascii[i]);
                }
            }
            printf("\n");
            line_n = 0;
            if (eof == 1)
                eof = 2;
        }
    }
    fclose(fp);
    return 0;
}